define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'clothmaking_customer/index' + location.search,
                    add_url: 'clothmaking_customer/add',
                    edit_url: 'clothmaking_customer/edit',
                    del_url: 'clothmaking_customer/del',
                    multi_url: 'clothmaking_customer/multi',
                    import_url: 'clothmaking_customer/import',
                    table: 'clothmaking_customer',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'customer_name', title: __('Customer_name'), operate: 'LIKE'},
                        {field: 'contacts', title: __('Contacts'), operate: 'LIKE'},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {field: 'tax_id', title: __('Tax_id'), operate: 'LIKE'},
                        {field: 'account', title: __('Account'), operate: 'LIKE'},
                        {field: 'deposit_bank', title: __('Deposit_bank'), operate: 'LIKE'},
                        {field: 'bank_id', title: __('Bank_id'), operate: 'LIKE'},
                        {field: 'payment', title: __('Payment'), searchList: {"transfer":__('Transfer'),"cash":__('Cash'),"honour":__('Honour'),"check":__('Check'),"thirty":__('Thirty'),"sixty":__('Sixty')}, formatter: Table.api.formatter.normal},
                        {field: 'ship_address', title: __('Ship_address'), operate: 'LIKE'},
                        {field: 'invoice_address', title: __('Invoice_address'), operate: 'LIKE'},
                        {field: 'consignee', title: __('Consignee'), operate: 'LIKE'},
                        {field: 'receive_connect_mobile', title: __('Receive_connect_mobile'), operate: 'LIKE'},
                        {field: 'user_ids', title: __('User_ids'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'remark', title: __('Remark'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
